public with sharing class AcceptanceLetterExtnCltr {

    public final Opportunity opp;
    public String CatalogID = ''; 
    public List<Catalog_Pricing__c> catalogPricing {get;set;}   
    
    public AcceptanceLetterExtnCltr(ApexPages.StandardController controller) {

           this.opp = (Opportunity)controller.getRecord();
           List<Opportunity> listOpportunity = [Select id,Quoted_Tuition_discount__c,Espa_Discount_Type__c,Quoted_Registration_discount__c,Payment_plan__c, account.Name,Catalog__r.id From Opportunity Where Id = :this.opp.Id];
           CatalogID = listOpportunity[0].Catalog__r.id;
           catalogPricing = [Select Campus__r.name,Enrollment_Fee__c,Catalog__r.id ,id,X10_Payments__c,X11_Payments__c,X3_Payments__c,X12_Payments__c, 
                                                        X5_Payments__c,X4_Payments__c,X6_payments__c,Early_Payoff__c from Catalog_Pricing__c where  Catalog__r.id = : CatalogID];           
    }
    
         public Decimal getTotal(){
          
           Decimal cos = 0.0;
           Decimal op = 1.0;
           Decimal cat = 1.0;        
         if( catalogPricing.size() > 0 )  
            {
              System.debug('+++++++++CAT' + catalogPricing[0].Enrollment_Fee__c);
              System.debug('+++++++++OPP' + Opp.Quoted_Registration_discount__c);
              
              if(catalogPricing[0].Enrollment_Fee__c != NULL ) {cat = catalogPricing[0].Enrollment_Fee__c; }
              if(Opp.Quoted_Registration_discount__c != NULL ) {op = Opp.Quoted_Registration_discount__c ;}
              cos = cat - (op * cat/100);
              return cos ; 
            }
          else  return cos;
     }
     
         public Decimal getTotalPlan(){
          
           Decimal cos = 0.0;
           Decimal op = 1.0;
           Decimal cat = 1.0;        
         if( catalogPricing.size() > 0 && opp.Payment_plan__c != NULL)  
            {
              if(opp.Payment_plan__c == '3' && catalogPricing[0].X3_Payments__c != NULL) {cat = catalogPricing[0].X3_Payments__c; }
              if(opp.Payment_plan__c == '4' && catalogPricing[0].X4_Payments__c != NULL) {cat = catalogPricing[0].X4_Payments__c; }
              if(opp.Payment_plan__c == '5' && catalogPricing[0].X5_Payments__c != NULL) {cat = catalogPricing[0].X5_Payments__c; }
              if(opp.Payment_plan__c == '6' && catalogPricing[0].X6_Payments__c != NULL) {cat = catalogPricing[0].X6_Payments__c; } 
              if(opp.Payment_plan__c == '10' && catalogPricing[0].X10_Payments__c != NULL) {cat = catalogPricing[0].X10_Payments__c; }
              if(opp.Payment_plan__c == '11' && catalogPricing[0].X11_Payments__c != NULL) {cat = catalogPricing[0].X11_Payments__c; }
              if(opp.Payment_plan__c == '12' && catalogPricing[0].X12_Payments__c != NULL) {cat = catalogPricing[0].X12_Payments__c; } 
              if((opp.Payment_plan__c == 'Early payoff' || opp.Payment_plan__c == 'Pago anticipado' || opp.Payment_plan__c == '1') && catalogPricing[0].Early_Payoff__c != NULL) {cat = catalogPricing[0].Early_Payoff__c; }
              
              if(Opp.Quoted_Tuition_discount__c != NULL ) {op = Opp.Quoted_Tuition_discount__c ;}
              System.debug('+++++++++oppppppppp' + op );
              System.debug('+++++++++cattttttt' + cat);              

              cos = cat - (op * cat/100);
              return cos ; 
            }
          else  return cos;
     }

     
         public Decimal getCostPlan(){
          
           Decimal cosb = 0.0;
        
         if( catalogPricing.size() > 0 && opp.Payment_plan__c != NULL)  
            {

              
              if(opp.Payment_plan__c == '3' && catalogPricing[0].X3_Payments__c != NULL) {cosb = catalogPricing[0].X3_Payments__c; }
              if(opp.Payment_plan__c == '4' && catalogPricing[0].X4_Payments__c != NULL) {cosb = catalogPricing[0].X4_Payments__c; }
              if(opp.Payment_plan__c == '5' && catalogPricing[0].X5_Payments__c != NULL) {cosb = catalogPricing[0].X5_Payments__c; }
              if(opp.Payment_plan__c == '6' && catalogPricing[0].X6_Payments__c != NULL) {cosb = catalogPricing[0].X6_Payments__c; }
              if(opp.Payment_plan__c == '10' && catalogPricing[0].X10_Payments__c != NULL) {cosb = catalogPricing[0].X10_Payments__c; }
              if(opp.Payment_plan__c == '11' && catalogPricing[0].X11_Payments__c != NULL) {cosb = catalogPricing[0].X11_Payments__c; }
              if(opp.Payment_plan__c == '12' && catalogPricing[0].X12_Payments__c != NULL) {cosb = catalogPricing[0].X12_Payments__c; } 
              if((opp.Payment_plan__c == 'Early payoff' || opp.Payment_plan__c == '1') && catalogPricing[0].Early_Payoff__c != NULL) {cosb = catalogPricing[0].Early_Payoff__c; }                            
              return cosb ; 
            }
          else  return cosb ;
     }
     

       public String getDat()
       {
           String dow = '';
           String day= String.valueOf(system.now().day());
           String shortDayOfweek = system.now().format('EEEEE');
           Integer month= system.now().month();
           String year= String.valueOf(system.now().year());
           String[] mth = new String[]{'enero','febrero','marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','diciembre'};
           if(shortDayOfWeek == 'Sunday'){dow = 'domingo';}
           if(shortDayOfWeek == 'Monday'){dow = 'lunes';}
           if(shortDayOfWeek == 'Tuesday'){dow = 'martes';}
           if(shortDayOfWeek == 'Wednesday'){dow = 'miércoles';}
           if(shortDayOfWeek == 'Thursday'){dow = 'jueves';}
           if(shortDayOfWeek == 'Friday'){dow = 'viernes';}
           if(shortDayOfWeek == 'Saturday'){dow = 'sábado';}

           String Sdate = dow + ', ' + day + ' de ' + mth[month-1] + ' de ' + year ;
                           
           return Sdate ;
          
       }
 
       public Boolean getlst()
         {
             if(catalogPricing.size()>=1)
                 return True;
             else 
                 return False ;      
         }
}